Step 3: Querying (`degree` & `isfriend`)

Now let's answer questions about the network. These operations are simple lookups on our `adj` list.

Guidance for Step 3

  • `degree u`: A user's degree is the number of friends they have. This is simply the size of their friend list, `adj[u]`.
  • `isfriend u v`: To check if `u` and `v` are friends, we just need to see if `v` is present in `u`'s friend list, `adj[u]`.
  • Your Task: Fill in the blanks to implement the query commands.
...
    elif op == "degree":
        u = int(parts[1])
        
        # --- BLANK 3 ---
        # The degree is the number of friends in user u's list.
        print(f"{_____________}")

    elif op == "isfriend":
        u, v = int(parts[1]), int(parts[2])

        # --- BLANK 4 ---
        # To check if v is a friend of u, we search u's friend list.
        if ________________:
            print("yes")
        else:
            print("no")

    elif op == "count_greater":
...

                
Copied!